//
//  WMEFindHeadCollectionViewCell.m
//  everyDay_duiTang
//
//  Created by 恩叔 on 16/2/25.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMEFindHeadCollectionViewCell.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>

@interface WMEFindHeadCollectionViewCell ()
@property (nonatomic, retain)UIImageView *img;
@property (nonatomic, retain)UILabel *titleName;

@end

@implementation WMEFindHeadCollectionViewCell
- (void)dealloc
{
    [_dic release];
    [_img release];
    [_titleName release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.img = [[UIImageView alloc] init];
        [self.contentView addSubview:_img];
        [_img release];
        
        self.titleName = [[UILabel alloc] init];
//        _titleName.backgroundColor = [UIColor redColor];
        _titleName.font = [UIFont systemFontOfSize:15];
        _titleName.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_titleName];
        [_titleName release];
    }
    return self;
}

- (void)setDic:(NSDictionary *)dic
{
    if (_dic != dic) {
        [_dic release];
        _dic = [dic retain];
        [_img sd_setImageWithURL:[NSURL URLWithString:_dic[@"icon_url"]]];
        _titleName.text = _dic[@"name"];
    }
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    __block __typeof(&*self)bs = self;
    [_img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bs.mas_left).with.offset(0);
        make.right.equalTo(bs.mas_right).with.offset(0);
        make.top.equalTo(bs.mas_top).with.offset(0);
        make.bottom.equalTo(bs.mas_bottom).with.offset(-20);
    }];
    
    [_titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bs.mas_left).with.offset(0);
        make.right.equalTo(bs.mas_right).with.offset(0);
        make.top.equalTo(_img.mas_bottom).with.offset(0);
        make.bottom.equalTo(bs.mas_bottom).with.offset(0);
    }];
}

@end
